import { pathToFileURL } from "url";
import { Config } from "../types/config";
import { buildSync } from "esbuild";

export async function loadUserConfig(dirname: string) {
    buildSync({
        absWorkingDir: dirname,
        platform: "node",
        entryPoints: ["webdpl.config.ts"],
        outfile: "webdpl.config.mjs",
        // bundle: true,
        format: "esm",
        // external: ['esbuild'],
    });

    const filename = dirname + "/webdpl.config.mjs";

    const module = await import(pathToFileURL(filename).href);

    return module.default as Config;
}
